package net.avh4.scratch.rpg;

import java.io.IOException;

/**
 * Generates a landmass by performing a random walk from a starting point.
 * @author vonderha
 * @see <a href="http://en.wikipedia.org/wiki/Random_walk">Wikipedia - Random Walk</a>
 */
public class RandomWalkWorldMap extends CachedWorldMap {

	public RandomWalkWorldMap() throws IOException {
		super();
		generate(20,15);
	}
	
	private void generate(int startX, int startY) {
		int x = startX;
		int y = startY;
		setTile(x,y,0);
		for (int t = 0; t < 250; t++) {
			switch (rand.nextInt(4)) {
			case 0: x++; break;
			case 1: x--; break;
			case 2: y++; break;
			case 3: y--; break;
			default: assert(false);
			}
			setTile(x,y,0);
		}
	}

}
